<?php
if (!defined('CMS_SYSTEM')) die();
if ($disable_site) {
	echo "<center style=\"margin-top:200px;font-weight:bold\">".$disable_message ."</center>";
}else{
global $db,$Default_Temp, $time, $currentlang,$prefix;
//Phan cap nhat noi dung lien he khi ho nhan submit
if(isset($_POST['submit_up']) && $_POST['submit_up'] == 1) {
	$person = $escape_mysql_string(trim($_POST['person']));
	$address = $escape_mysql_string(trim($_POST['address']));
	$phone = $_POST['phone'];
	$email = $escape_mysql_string(trim($_POST['email']));
	$message = $escape_mysql_string(trim($_POST['content']));
    if(!is_email($email) || empty($message)) {
		$err_mess = "<font color=\"red\">"._ERROR_CT."</font><br>";
		$err = 1;
	}
	if(!isset($err)) 
	{
		$db->sql_query("INSERT INTO {$prefix}_contact (content, ctname, address, phone, email, time, alanguage, response) VALUES ('$message', '$person','$address', '$phone', '$email', '".time()."', '$currentlang', '')");
	      include_once("templates/".$Default_Temp."/header.php");
		  include_once("templates/".$Default_Temp."/banner.php");
		  include_once("templates/".$Default_Temp."/menu.php");
		  /*
		   * Phan loc ra tat ca san pham
		   * Le duc vien
		   */
		 echo "<div id=\"wrapper\">";
			 echo "<div class=\"content fix\">";
			     //Noi dung phan loc tat ca san pham
			     echo "<div class=\"w720 fl\">";
			       echo "<div class=\"common\">";
			            echo "<div class=\"title\">";
						 echo "<h1 class=\"text\"><a href=\"".url_sid("index.php?f=contact")."\"><span>"._CONTACTS."</span></a></h1>";
			    		echo "</div>";
					    echo "<div class=\"wrap fix\">";
					         echo "<div class=\"contact\">";
					              echo "<fieldset>";
										echo "<legend>"._CONTACT_INFO."</legend>";
										echo "<ul>";
											echo "<li>";
												echo "<center>"._SENT."</center>";
											echo "</li>";
										echo "</ul>";
							 	echo "</fieldset>";
					         echo "</div>";
					    echo "</div>";
			       echo "</div>";
			     echo "</div>";
			     include_once("templates/".$Default_Temp."/rightbody.php");
			 echo "</div>";
			 themeSlideShow(8);
			 themeFooter();
		 echo "</div>";
		 /*
		  * Ket thuc phan san pham
		  * 
		  */
		     
		include_once("templates/".$Default_Temp."/footer.php");
		 /*
		  * Ket thuc phan san pham
		  * 
		  */
		//echo "<META HTTP-EQUIV=\"refresh\" content=\"5;URL= ".url_sid("index.php")."\">";
		include_once("templates/".$Default_Temp."/footer.php");
		echo "<META HTTP-EQUIV=\"refresh\" content=\"5;URL= ".url_sid("index.php")."\">";
		exit();
	}else{
		
		$person = $address = $phone = $email = $message = "";
	}
}

//Ket thuc phan insert du lieu
include_once("templates/".$Default_Temp."/header.php");
  include_once("templates/".$Default_Temp."/banner.php");
  include_once("templates/".$Default_Temp."/menu.php");
  /*
   * Phan loc ra tat ca san pham
   * Le duc vien
   */
 echo "<div id=\"wrapper\">";
	 echo "<div class=\"content fix\">";
	     //Noi dung phan loc tat ca san pham
	     echo "<div class=\"w720 fl\">";
	       echo "<div class=\"common\">";
	            echo "<div class=\"title\">";
				 echo "<h1 class=\"text\"><a href=\"".url_sid("index.php?f=contact")."\"><span>"._CONTACTS."</span></a></h1>";
			    echo "</div>";
			    echo "<div class=\"wrap fix\">";
			         echo "<div class=\"contact\">";
			              echo "<form action=\"".url_sid("index.php?f=$module_name")."\" method=\"post\" id=\"contactForm\">";
                          $resultadd = $db->sql_query("SELECT address,map FROM ".$prefix."_contact_add WHERE address!='' AND alanguage='$currentlang'");
                          list($address_ct,$map) = $db->sql_fetchrow($resultadd);
                          if($db->sql_numrows($resultadd) > 0) 
					      {
			                 echo "<fieldset>";
										echo "<legend>"._CONTACT_INFO."</legend>";
										echo "<span>$address_ct</span>";
							 echo "</fieldset>";
					      }else{
					      	echo "<fieldset>";
										echo "<legend>"._CONTACT_INFO."</legend>";
										echo "<ul>";
											echo "<li>";
												echo "<center>"._CONTACT_INFO_NULL."</center>";
											echo "</li>";
										echo "</ul>";
							 echo "</fieldset>";
					      }
					      if($map)
					      {
					      echo "<div class=\"map\">";
										echo "<img id=\"mapcompany\" src=\"$path_upload/$module_name/$map\" alt=\""._CONTACT_MAP."\" />";
						  echo "</div>";
					      }else{
					      	echo "<div class=\"map\">";
										echo "<center>"._CONTACT_MAP_NULL."</center>";
						      echo "</div>";
					      }
						  
						  echo "<div class=\"notice\">";
									echo "<span>"._CONTACT_CUSTOMER."</span>";
						  echo "</div>";
						  echo "<div class=\"line fix\">";
										echo "<div class=\"w120 fl\">";
											echo "<label for=\"person\">"._CONTACT_EMP.":</label>";
										echo "</div>";
										echo "<div class=\"fl w550\">";
											echo "<input type=\"text\" class=\"inputForm w250\" name=\"person\" id=\"person\" maxlength=\"150\"/><span class=\"field_notice\">*</span>";
										echo "</div>";
									echo "</div>";
									echo "<div class=\"line fix\">";
										echo "<div class=\"w120 fl\">";
											echo "<label for=\"address\">"._CONTACT_ADDRESS.":</label>";
										echo "</div>";
										echo "<div class=\"fl w550\">";
											echo "<input type=\"text\" class=\"inputForm w250\" name=\"address\" maxlength=\"150\" id=\"address\"/><span class=\"field_notice\">*</span>";
										echo "</div>";
									echo "</div>";
									echo "<div class=\"line fix\">";
										echo "<div class=\"w120 fl\">";
											echo "<label for=\"phone\">"._CONTACT_PHONE.":</label>";
										echo "</div>";
										echo "<div class=\"fl w550\">";
											echo "<input type=\"text\" class=\"inputForm w250\" name=\"phone\" maxlength=\"12\" id=\"phone\"/><span class=\"field_notice\">*</span>";
										echo "</div>";
									echo "</div>";
									echo "<div class=\"line fix\">";
										echo "<div class=\"w120 fl\">";
											echo "<label for=\"email\">"._CONTACT_EMAIL.":</label>";
										echo "</div>";
										echo "<div class=\"fl w550\">";
											echo "<input type=\"text\" class=\"inputForm w250\" name=\"email\" id=\"email\"/><span class=\"field_notice\">*</span>";
										echo "</div>";
									echo "</div>";
									echo "<div class=\"line fix\">";
										echo "<div class=\"w120 fl\">";
											echo "<label for=\"content\">"._CONTACT_CONTENT.":</label>";
										echo "</div>";
										echo "<div class=\"fl w550\">";
											echo "<textarea class=\"inputForm h120 w500\" name=\"content\" maxlength=\"1000\" id=\"content\"></textarea><span class=\"field_notice\">*</span>";
										echo "</div>";
									echo "</div>";
									echo "<div class=\"line fix\">";
										echo "<div class=\"w120 fl\">&nbsp;</div>";
										echo "<div class=\"fl w550\">";
											echo "<input type=\"submit\" class=\"btnSubmit\" value=\""._CONTACT_SEND."\" name=\"submit\"/>";
											echo "<input type=\"reset\" class=\"btnReset\" value=\""._CONTACT_RESET."\" name=\"reset\"/>";
										echo "</div>";
									echo "</div>";
									echo "<input type=\"hidden\" name=\"submit_up\" value=\"1\">";
			              echo "</form>";
			         echo "</div>";
			    echo "</div>";
	       echo "</div>";
	     echo "</div>";
	     include_once("templates/".$Default_Temp."/rightbody.php");
	 echo "</div>";
	 themeSlideShow(8);
	 themeFooter();
 echo "</div>";
 /*
  * Ket thuc phan san pham
  * 
  */
 	echo "<script type=\"text/javascript\" src=\"templates/".$Default_Temp."/js/validate.js\"></script><!--Dùng cho trang liên hệ-->";			
	echo "<script type=\"text/javascript\" src=\"templates/".$Default_Temp."/js/map.js\"></script><!--Dùng cho trang liên hệ-->";
 echo "<script type=\"text/javascript\">";
		echo "$(function(){";
		
			echo "$('#contactForm').validate({";
				echo "errorPlacement: function(error, element){";
					echo "$(element).next('.field_notice').hide();";
					echo "$(element).after(error);";
				echo "},";
				echo "success       : function(label){";
					echo "label.addClass('right').text('OK!');";
				echo "},";
				echo "rules : {";
					echo "person : {";
						echo "required   : true,";
						echo "maxlength: 150";
					echo "},";
					echo "address : {";
						echo "required   : true,";
						echo "maxlength: 150";
					echo "},";
					echo "phone : {";
						echo "required   : true,";
						echo "number: true,";
						echo "maxlength: 12,";
						echo "minlength: 8";
					echo "},";
					echo "email : {";
						echo "required   : true,";
						echo "email: true";
					echo "},";
					echo "content : {";
						echo "required   : true,";
						echo "maxlength: 1000";
					echo "}";
				echo "},";
				echo "messages : {";
					echo "person : {";
						echo "required   : \""._PLEASE_COMPANY."\",";
						echo "maxlength: \""._PLEASE_NAME_MAX."\"";
					echo "},";
					echo "address : {";
						echo "required   : \""._PLEASE_ADDRESS."\",";
						echo "maxlength: \""._PLEASE_ADDRESS_MAX."\"";
					echo "},";
					echo "phone : {";
						echo "required   : \""._PLEASE_PHONE."\",";
						echo "number: \""._PLEASE_PHONE_NUMBER."\",";
						echo "maxlength: \""._PLEASE_PHONE_MAX."\",";
						echo "minlength: \""._PLEASE_PHONE_MIN."\"";
					echo "},";
					echo "email : {";
						echo "required   : \""._PLEASE_EMAIL."\",";
						echo "email: \""._PLEASE_EMAIL_ERROR."\"";
					echo "},";
					echo "content : {";
						echo "required   : \""._PLEASE_CONTACT."\",";
						echo "maxlength: \""._PLEASE_CONTACT_MAX."\"";
					echo "}	";
				echo "},";
			echo "});";
		echo "});";
	echo "</script>";
}
?>